﻿using ArtMath.Attribute;
using ArtMath.Component.Line;
using ArtMath.Component.Point;
using ArtMath.PointCollection;
using System;
using System.Collections.Generic;

namespace ArtMath.Component.Polygon
{
    /// <summary>
    /// 梯形基类
    /// </summary>
    [Serializable]
    public abstract class TrapezoidBase : PolygonBase
    {
        public TrapezoidBase(SketchPad pad, string name, ToolTypeName toolType, bool addToList = true) : base(pad, name, toolType, addToList)
        {
            for (int i = 0; i < 4; i++)
            {
                Lines.Add(null);
            }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}1", "Hemline")]
        public LineSegmentBase Hemline1
        {
            get { return Lines[1]; }
            set { SetLine(1, value); }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}2", "Hemline")]
        public LineSegmentBase Hemline2
        {
            get { return Lines[3]; }
            set { SetLine(3, value); }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}1", "Waist")]
        public virtual LineSegmentBase Waist1
        {
            get { return Lines[0]; }
            set { SetLine(0, value); }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}2", "Waist")]
        public virtual LineSegmentBase Waist2
        {
            get { return Lines[2]; }
            set { SetLine(2, value); }
        }
        public override PointCollectionBase[] GetInPointMovingRange(PointBase movePoint, Base sender = null)
        {
            switch (CountMovablePoints())
            {
                case 1:
                    if (movePoint == Hemline1.Point1)
                    {
                        return new PointCollectionBase[] { new Ray(Waist2.Point1.NewXY, Hemline2.Point1.NewXY.GetAngle(Waist1.Point1.NewXY)) { Exceptions = new HashSet<PointCollectionBase>() { new StraightLine(Waist1.Point1.NewXY, Waist2.NewSlope) } } };
                    }
                    else if (movePoint == Waist2.Point1)
                    {
                        return new PointCollectionBase[] { new Ray(Hemline1.Point1.NewXY, Waist1.Point1.NewXY.GetAngle(Hemline2.Point1.NewXY)) { Exceptions = new HashSet<PointCollectionBase>() { new StraightLine(Hemline2.Point1.NewXY, Waist1.NewSlope) } } };
                    }
                    else if (movePoint == Waist1.Point1)
                    {
                        return new PointCollectionBase[] { new Ray(Hemline2.Point1.NewXY, Waist2.Point1.NewXY.GetAngle(Hemline1.Point1.NewXY)) { Exceptions = new HashSet<PointCollectionBase>() { new StraightLine(Hemline1.Point1.NewXY, Waist2.NewSlope) } } };
                    }
                    else if (movePoint == Hemline2.Point1)
                    {
                        return new PointCollectionBase[] { new Ray(Waist1.Point1.NewXY, Hemline1.Point1.NewXY.GetAngle(Waist2.Point1.NewXY)) { Exceptions = new HashSet<PointCollectionBase>() { new StraightLine(Waist2.Point1.NewXY, Waist1.NewSlope) } } };
                    }
                    break;
            }
            return base.GetInPointMovingRange(movePoint, sender);
        }
    }
}
